#!/bin/bash

echo "========================================"
echo "语音对话系统 - 一键启动脚本 (Linux版本)"
echo "========================================"
echo

# 检查Python环境
if ! command -v python3 &> /dev/null; then
    echo "❌ 错误: 未找到Python3，请先安装Python3"
    exit 1
fi

# 检查Node.js环境
if ! command -v node &> /dev/null; then
    echo "❌ 错误: 未找到Node.js，请先安装Node.js"
    exit 1
fi

# 检查pnpm环境
if ! command -v pnpm &> /dev/null; then
    echo "❌ 错误: 未找到pnpm，请先安装pnpm"
    echo "安装命令: npm install -g pnpm"
    exit 1
fi

echo "✅ 环境检查通过"
echo

# 启动前端服务
echo "🚀 正在启动前端服务..."
cd frontend
pnpm install &
FRONTEND_PID=$!

echo "⏳ 等待前端依赖安装完成..."
sleep 10

# 启动后端服务
echo "🔧 正在启动后端服务..."
cd ../backend
python3 simple_test.py &
BACKEND_PID=$!

echo
echo "========================================"
echo "启动完成！"
echo "========================================"
echo
echo "📱 前端地址: http://localhost:3000"
echo "🔧 后端测试: 查看后端窗口输出"
echo
echo "💡 提示:"
echo "   - 按 Ctrl+C 停止所有服务"
echo "   - 前端服务PID: $FRONTEND_PID"
echo "   - 后端服务PID: $BACKEND_PID"
echo

# 等待用户中断
trap "echo '正在停止服务...'; kill $FRONTEND_PID $BACKEND_PID 2>/dev/null; exit" INT
wait 